GdkWindowX11: Keep the impl window cairo surface around until destroy
authorAlexander Larsson <alexl@redhat.com>
Thu, 30 Oct 2014 09:30:33 +0000 (10:30 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 30 Oct 2014 09:32:47 +0000 (10:32 +0100)
We used to have a weak ref to the cairo surface and it was keep
alive by the references in the normal windows, but that reference
was removed by d48adf9cee7e340acd7f8b9a5f9716695352b848, causing
us to constantly create and destroy the surface.

https://bugzilla.gnome.org/show_bug.cgi?id=738648

gdk/x11/gdkwindow-x11.c

index cdecf66d98ea05e46f5a67ed74c6b8f49fc12c59..1a7281d61da46617daf4670b3f9742544eedf93f 100644 (file)
@@ -180,8 +180,6 @@ _gdk_x11_window_get_toplevel (GdkWindow *window)
   return impl->toplevel;
 }
 
-static const cairo_user_data_key_t gdk_x11_cairo_key;
-
 /**
  * _gdk_x11_window_update_size:
  * @impl: a #GdkWindowImplX11.
@@ -441,14 +439,6 @@ gdk_x11_window_end_frame (GdkWindow *window)
  * X11 specific implementations of generic functions *
  *****************************************************/
 
-static void
-gdk_x11_cairo_surface_destroy (void *data)
-{
-  GdkWindowImplX11 *impl = data;
-
-  impl->cairo_surface = NULL;
-}
-
 static cairo_surface_t *
 gdk_x11_create_cairo_surface (GdkWindowImplX11 *impl,
                              int width,
@@ -479,16 +469,12 @@ gdk_x11_ref_cairo_surface (GdkWindow *window)
 #ifdef HAVE_CAIRO_SURFACE_SET_DEVICE_SCALE
       cairo_surface_set_device_scale (impl->cairo_surface, impl->window_scale, impl->window_scale);
 #endif
-      
-      if (impl->cairo_surface)
-       cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
-                                    impl, gdk_x11_cairo_surface_destroy);
 
       if (WINDOW_IS_TOPLEVEL (window) && impl->toplevel->in_frame)
         hook_surface_changed (window);
     }
-  else
-    cairo_surface_reference (impl->cairo_surface);
+
+  cairo_surface_reference (impl->cairo_surface);
 
   return impl->cairo_surface;
 }
@@ -1318,8 +1304,8 @@ gdk_x11_window_destroy (GdkWindow *window,
   if (impl->cairo_surface)
     {
       cairo_surface_finish (impl->cairo_surface);
-      cairo_surface_set_user_data (impl->cairo_surface, &gdk_x11_cairo_key,
-                                   NULL, NULL);
+      cairo_surface_destroy (impl->cairo_surface);
+      impl->cairo_surface = NULL;
     }
 
   if (!recursing && !foreign_destroy)